import type { DeptTree, Device } from './model';

import type { ID } from '#/api/common';
import type { Page } from '#/interface/page';

import { requestClient } from '#/api/request';

enum Api {
  // devicetList = '/iot/device/page',
  // deptNodeInfo = '/system/dept/list/exclude',
  // deviceAdd = '/iot/device/add',
  // deviceInfo = '/iot/device/detail',
  // deviceUpdate = '/iot/device/update',
  // deviceRemove = '/iot/device/remove',
  // root = '/system/dept',
  addGroup = '/iot/deviceGroup/save',
  bindDevice = '/iot/deviceGroup/bindDevice',
  delGroup = '/iot/deviceGroup/remove',
  groupDetail = '/iot/deviceGroup/detail',
  groupTree = '/iot/deviceGroup/tree',
  unbindDevice = '/iot/deviceGroup/unbindDevice',
  updateGroup = '/iot/deviceGroup/update',
}

/**
 * 新增分组
 * @param data 参数
 */
export function addGroup(data: Partial<Device>) {
  return requestClient.postWithMsg<void>(Api.addGroup, data);
}

/**
 * 修改分组
 * @param data 参数
 */
export function updateGroup(data: Partial<Device>) {
  return requestClient.postWithMsg<void>(Api.updateGroup, data);
}

/**
 * 删除分组
 * @param id
 */
export function delGroup(id: ID) {
  return requestClient.postWithMsg<void>(`${Api.delGroup}?id=${id}`);
}

/**
 * 分组树
 * @returns list
 */
export function groupTree() {
  return requestClient.get<DeptTree[]>(Api.groupTree);
}

/**
 * 分组详情
 * @returns list
 */
export function groupDetail(id: ID) {
  return requestClient.get<Page<Device>>(`${Api.groupDetail}?id=${id}`);
}

/**
 * 绑定设备
 * @param data 参数
 */
export function bindDevice(data: Partial<Device>) {
  return requestClient.postWithMsg<void>(Api.bindDevice, data);
}

/**
 * 解绑设备
 * @param data 参数
 */
export function unbindDevice(data: Partial<Device>) {
  return requestClient.postWithMsg<void>(Api.unbindDevice, data);
}
